home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Amiga_Mail_Vol2 / Archives / Plain / so90 / screens20code.txt < prev    next >
Encoding:
Text File  |  1990-10-24  |  32.7 KB  |  873 lines

  1. (c)  Copyright 1990 Commodore-Amiga, Inc.   All rights reserved.
  2. The information contained herein is subject to change without notice,
  3. and is provided "as is" without warranty of any kind, either expressed
  4. or implied.  The entire risk as to the use of this information is
  5. assumed by the user.
  6.  
  7. /* 
  8.  * V36 Simple public screen example.
  9.  * 
  10.  * Compiled with SAS C 5.10:  lc -cfist -v -L pub.c
  11.  * Use V36 include files.
  12.  */
  13.  
  14. #include <intuition/intuition.h>
  15. #include <intuition/screens.h>
  16. #include <graphics/displayinfo.h>
  17. #include <libraries/gadtools.h>
  18. #include <exec/memory.h>
  19. #include <dos/dosextens.h>
  20.  
  21. #include <clib/exec_protos.h>
  22. #include <clib/gadtools_protos.h>
  23. #include <clib/intuition_protos.h>
  24.  
  25. #include <pragmas/exec_pragmas.h>
  26. #include <pragmas/gadtools_pragmas.h>
  27. #include <pragmas/intuition_pragmas.h>
  28.  
  29. struct IntuitionBase *IntuitionBase;
  30. struct Library *GadToolsBase;
  31.  
  32. static UWORD dri_Pens[] =
  33. {0, 1, 1, 2, 1, 3, 1, 0, 3, ~0};
  34.  
  35. /* Gadtools menu stuff */
  36. #define QUIT 1
  37. struct NewMenu sdm_menu[] =
  38. {
  39.     {NM_TITLE, "Project", 0, 0, 0, 0,},
  40.     {NM_ITEM, "Quit", "Q", 0, 0, (void *) QUIT,},
  41.     {NM_END, NULL, 0, 0, 0, 0,},
  42. };
  43.  
  44. struct EasyStruct failedES =
  45. {
  46.     sizeof(struct EasyStruct), 0, "AMPub",
  47.     "%s",
  48.     "OK",
  49. };
  50.  
  51. void main(void);
  52.  
  53. void
  54. main(void)
  55. {
  56.  
  57.     struct Screen *pubscreen;
  58.     struct Window *window;
  59.     struct Menu *menu;
  60.     void *vi;
  61.  
  62.     struct IntuiMessage *msg;
  63.     UBYTE defaultpubname[MAXPUBSCREENNAME];
  64.     UWORD oldstatus;
  65.     UWORD oldmodes;
  66.     ULONG signal, wsignal, lastsignal, allocsignal;
  67.     ULONG oserror;
  68.     BOOL ABORT = FALSE;
  69.     BOOL CLOSEDOWN = FALSE;
  70.     struct Task *task;
  71.  
  72.     /* Fails silently if not V36 */
  73.     if (IntuitionBase = OpenLibrary("intuition.library", 36)) {
  74.         if (GadToolsBase = OpenLibrary("gadtools.library", 36)) {
  75.             if ((allocsignal = AllocSignal(-1)) != -1) {
  76.                 lastsignal = 1 << allocsignal;
  77.  
  78.                 /* We'll use our task address to get signaled when the last
  79.                  * visitor window leaves. */
  80.                 task = 
  81.                   (struct Task *)&((struct Process *)FindTask(NULL))->pr_Task;
  82.  
  83.                 /* Get the name of the currently default 
  84.                  * public screen (normally WB) */
  85.                 GetDefaultPubScreen(defaultpubname);
  86.  
  87.                 /* Note that no checking is done to make sure the 
  88.                  * public screen name is unique.  If the public name is 
  89.                  * not unique, OSERR_PUBNOTUNIQUE is returned in an
  90.                  * application supplied variable as data for the SA_ErrorCode
  91.                  * tag.  In this case however, if OpenScreen fails, for 
  92.                  * whatever reason, we just bail out.
  93.                  */
  94.  
  95.                 if (pubscreen = OpenScreenTags(NULL,
  96.                                  SA_DisplayID, HIRES_KEY,
  97.                                  SA_Depth, 2,
  98.                                  SA_Title,  "AmigaMail Test Public Screen",
  99.                                  SA_PubName,"AmigaMail Test Public Screen",
  100.  
  101.                                  SA_PubSig, allocsignal,
  102.                                  SA_PubTask, task, 
  103.                                           /* Normally you'd supply 0L, if you
  104.                                           * the task which opened the screen to
  105.                                           * be signaled.
  106.                                           */
  107.                                  SA_Pens, dri_Pens, SA_ErrorCode, &oserror,
  108.                                  TAG_END)) {
  109.                     if (menu = CreateMenus(sdm_menu, TAG_DONE)) {
  110.                         if (window = OpenWindowTags(NULL,
  111.                                       WA_Top, pubscreen->BarHeight + 1,
  112.                                       WA_Height, pubscreen->Height 
  113.                                                  - (pubscreen->BarHeight + 1),
  114.                                       WA_CustomScreen, pubscreen,
  115.                                       WA_IDCMP, MENUPICK,
  116.                                       WA_Flags, ACTIVATE|BACKDROP|
  117.                                                     BORDERLESS|NOCAREREFRESH,
  118.                                       TAG_END)) {
  119.  
  120.                             vi = GetVisualInfo(pubscreen, TAG_END);
  121.                             if (LayoutMenus(menu, vi, TAG_DONE)) {
  122.                                 SetMenuStrip(window, menu);
  123.     
  124.                                 /* Now we have a screen, named "AmigaMail Test
  125.                                  * Public Screen", which is still marked 
  126.                                  * private, but ready to be made public.
  127.                                  */
  128.                                 oldstatus = PubScreenStatus(pubscreen, 0);
  129.                                 /* Now it is really public. We'll make it the
  130.                                  * default (and shanghai attempts to open 
  131.                                  * windows on the Workbench.
  132.                                  */
  133.                                 SetDefaultPubScreen(
  134.                                                "AmigaMail Test Public Screen");
  135.  
  136.                                 oldmodes = SetPubScreenModes(SHANGHAI|
  137.                                                              POPPUBSCREEN);
  138.     
  139.                                 wsignal = 1 << window->UserPort->mp_SigBit;
  140.  
  141.                                 do {
  142.                                     signal = Wait(wsignal|lastsignal);
  143.                                     /* The last visitor just left our screen */
  144.                                     if (signal & lastsignal) {
  145.                                         if (CLOSEDOWN)
  146.                                             if ((oldstatus = 
  147.                                                  PubScreenStatus(pubscreen, 
  148.                                                            PSNF_PRIVATE)) & 1)
  149.                                                 ABORT = TRUE;
  150.                                     }
  151.  
  152.                                     /* If not wsignal, this while-loop will not
  153.                                      * be executed. 
  154.                                      */
  155.                                     while(msg = (struct IntuiMessage *)
  156.                                           GetMsg(window->UserPort)) {
  157.                                     if (msg->Class == MENUPICK) {
  158.                                             if ((UWORD)(MENU_USERDATA
  159.                                                     (ItemAddress(menu, 
  160.                                                         msg->Code))) == QUIT) {
  161.                                             /* If we can't make our screen
  162.                                              * private again, we got 
  163.                                              * visitor window(s). Note
  164.                                              * window(s) you open without
  165.                                              * specifiying SA_PubScreenName, 
  166.                                              * are NOT considered visitor 
  167.                                              * windows.  So it's easy to try
  168.                                              * to make your public screen
  169.                                              * private again, without having
  170.                                              * to close down your own windows
  171.                                              * first.
  172.                                              */
  173.  
  174.                                             if ((oldstatus = 
  175.                                                  PubScreenStatus(pubscreen, 
  176.                                                           PSNF_PRIVATE)) & 1) {
  177.                                                 ABORT = TRUE;
  178.                                                 }
  179.                                             else {
  180.                                                 /* Close as soon as possible */
  181.                                                      CLOSEDOWN = TRUE;
  182.                                                     EasyRequest(window, 
  183.                                                                 &failedES, 
  184.                                                                 NULL, 
  185.                        "Can't make screen private.\nPlease close all windows");
  186.                                                 }
  187.                                             }
  188.                                         }
  189.                                         ReplyMsg((struct Message *)msg);
  190.                                     }
  191.                                 } while (ABORT == FALSE);
  192.  
  193.                                 /* Restore orignal default */
  194.                                 SetDefaultPubScreen(defaultpubname);
  195.                                 ClearMenuStrip(window);
  196.                                 FreeVisualInfo(vi);
  197.                             } else
  198.                                 EasyRequest(NULL, 
  199.                                             &failedES, 
  200.                                             NULL, 
  201.                                             "Can't layout menu's");
  202.                             CloseWindow(window);
  203.                         } else
  204.                             EasyRequest(NULL, 
  205.                                         &failedES, 
  206.                                         NULL, 
  207.                                         "Can't open window");
  208.                         FreeMenus(menu);
  209.                     } else EasyRequest(NULL, 
  210.                                        &failedES,
  211.                                        NULL, 
  212.                                        "Can't create menu's");
  213.                     CloseScreen(pubscreen);
  214.                 } else
  215.                     EasyRequest(NULL, 
  216.                                 &failedES, 
  217.                                 NULL, 
  218.                                 "Can't open public screen");
  219.                 FreeSignal(allocsignal);
  220.             } else
  221.             EasyRequest(NULL, &failedES, NULL, "No signal available");
  222.             CloseLibrary(GadToolsBase);
  223.         }
  224.     CloseLibrary(IntuitionBase);
  225.     }
  226. }
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278. /*
  279.  * V36 Clone Workbench screen
  280.  *
  281.  * Compiled with SAS C 5.10:  lc -cfist -v -L CloneWB.c
  282.  * Use V36 include files.
  283.  *
  284.  */
  285.  
  286. #include <stdio.h>
  287. #include <stdlib.h>
  288. #include <intuition/intuition.h>
  289. #include <intuition/screens.h>
  290. #include <graphics/displayinfo.h>
  291.  
  292. #include <clib/exec_protos.h>
  293. #include <clib/intuition_protos.h>
  294. #include <clib/graphics_protos.h>
  295.  
  296. #include <pragmas/exec_pragmas.h>
  297. #include <pragmas/intuition_pragmas.h>
  298. #include <pragmas/graphics_pragmas.h>
  299.  
  300. struct IntuitionBase *IntuitionBase;
  301. struct GfxBase *GfxBase;
  302.  
  303. struct EasyStruct failedES = {
  304.     sizeof(struct EasyStruct), 0, "CWB",
  305.     "%s",
  306.     "OK",
  307. };
  308.  
  309. void            main(void);
  310.  
  311. void
  312. main(void)
  313. {
  314.     struct Screen *wbscreen;
  315.     struct Screen *clonescreen;
  316.     struct Window *window;
  317.     struct ViewPort *vp;
  318.     struct IntuiMessage *msg;
  319.     ULONG modeID;
  320.  
  321.     struct DisplayInfo displayinfo;
  322.     struct MonitorInfo monitorinfo;
  323.     struct DimensionInfo dimensioninfo;
  324.     struct NameInfo nameinfo;
  325.     struct DrawInfo *drawinfo;
  326.  
  327.     ULONG result;
  328.  
  329.     /* Fails silently when not V36 */
  330.     if (IntuitionBase = OpenLibrary("intuition.library", 36)) {
  331.         if (GfxBase = OpenLibrary("graphics.library", 36)) {
  332.  
  333.             if (wbscreen = LockPubScreen("Workbench")) {
  334.                 /* Using intuition.library/GetScreenDrawInfo(), we get the pen
  335.                  * array we'll use for the screen clone the easy way. */
  336.                 drawinfo = GetScreenDrawInfo(wbscreen);
  337.  
  338.                 vp = &(wbscreen->ViewPort);
  339.                 /* Use graphics.library/GetVPModeID() to get the ModeID of the
  340.                  * Workbench screen. */
  341.                 if ((modeID = GetVPModeID(vp)) != INVALID_ID) {
  342.                     /* OK, we got a valid ModeID for the Workbench 
  343.                      * screen (surprise) */
  344.  
  345.                     /* With just the ModeID, the lock on the Workbench 
  346.                      * screen & drawinfo->dri_Pens we're able to clone the
  347.                      * Workbench exactly, displaymode and all. When you want 
  348.                      * to know everything there is to know about this 
  349.                      * displaymode, use graphics.library/GetDisplayInfoData().
  350.                      */
  351.                     /* 'result' is the actual # of bytes copies
  352.                      * into the buffer.
  353.                      * See graphics/displayinfo.h for definitions
  354.                      * of the various structures.
  355.                      */
  356.                     result = GetDisplayInfoData(NULL, 
  357.                                                 (UBYTE *)&monitorinfo, 
  358.                                                 sizeof(struct MonitorInfo), 
  359.                                                 DTAG_MNTR, modeID);
  360.                     result = GetDisplayInfoData(NULL, 
  361.                                                 (UBYTE *)&displayinfo,
  362.                                                 sizeof(struct DisplayInfo),
  363.                                                 DTAG_DISP, modeID);
  364.                     result = GetDisplayInfoData(NULL,
  365.                                                 (UBYTE *)&dimensioninfo, 
  366.                                                 sizeof(struct DimensionInfo),
  367.                                                 DTAG_DIMS,
  368.                                                 modeID);
  369.                     result = GetDisplayInfoData(NULL,
  370.                                                 (UBYTE *)&nameinfo,
  371.                                                 sizeof(struct NameInfo),
  372.                                                 DTAG_NAME, 
  373.                                                 modeID);
  374.  
  375.                     /* If you don't want to clone the workbench exactly,
  376.                      * you could use one of the other overscan modes
  377.                      * and/or min/max.
  378.                      * dimensions in dimensioninfo or open a regular screen.
  379.                      */
  380.                     if (clonescreen = OpenScreenTags(NULL,
  381.                         /* Could use STDSCREENWIDTH/HEIGHT for non-scrollable
  382.                          * screens. Those make */
  383.                         SA_Width, wbscreen->Width,
  384.  
  385.                         /* OpenScreen() use the textoverscan values */
  386.                         SA_Height, wbscreen->Height,        
  387.  
  388.                         SA_DisplayID, modeID,
  389.  
  390.                         SA_Depth, wbscreen->BitMap.Depth,
  391.  
  392.                         /*Workbench always sizes up to OSCAN_TEXT, so do we */
  393.                         SA_Overscan, OSCAN_TEXT,
  394.  
  395.                         SA_Pens, drawinfo->dri_Pens,
  396.  
  397.                         SA_Title, nameinfo.Name,
  398.  
  399.                         /* Doesn't hurt for screens which don't scroll */
  400.                         SA_AutoScroll, TRUE,
  401.  
  402.                         TAG_END)) {
  403.  
  404.                         if (window = OpenWindowTags(NULL,
  405.                             WA_Top, clonescreen->BarHeight + 1,
  406.                             WA_Height, clonescreen->Height 
  407.                                                 - (clonescreen->BarHeight + 1),
  408.                             WA_CustomScreen, clonescreen,
  409.                             WA_MinWidth, 320,
  410.                             WA_MinHeight, 100,
  411.                             WA_MaxWidth, clonescreen->Width,
  412.                             WA_MaxHeight, clonescreen->Height,
  413.  
  414.                             /* I'm only interested in CLOSEWINDOW messages */
  415.                             WA_IDCMP, CLOSEWINDOW, 
  416.                             WA_Flags, WINDOWSIZING|WINDOWDRAG|
  417.                                            WINDOWDEPTH|WINDOWCLOSE|ACTIVATE,
  418.                             WA_Title, "Close to exit.",
  419.                             TAG_END)) {
  420.  
  421.                             /* Wait for the closewindow message */
  422.                             WaitPort(window->UserPort);
  423.                             /* And remove message from the port */
  424.                             while(msg = (struct IntuiMessage *)
  425.                                   GetMsg(window->UserPort))
  426.                                 ReplyMsg((struct Message *)msg);
  427.                             CloseWindow(window);
  428.                         } else
  429.                             EasyRequest(NULL, &failedES, NULL, 
  430.                                         "Can't open window");
  431.                         CloseScreen(clonescreen);
  432.                     } else
  433.                         EasyRequest(NULL, &failedES, NULL, 
  434.                                     "Can't open screen");
  435.                 } else
  436.                     EasyRequest(NULL, &failedES, NULL, "Invalide ModeID");
  437.                 FreeScreenDrawInfo(wbscreen, drawinfo);
  438.                 UnlockPubScreen(NULL, wbscreen);
  439.             } else
  440.                 EasyRequest(NULL, &failedES, NULL, 
  441.                             "Can't lock Workbench screen");
  442.             CloseLibrary(GfxBase);
  443.         }
  444.         CloseLibrary(IntuitionBase);
  445.     }
  446. }
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457. /* 
  458.  * V36 Screen Displaymode selector example
  459.  * 
  460.  * Compiled with SAS C 5.05:  lc -cfist -v -L ScreenDisplayModes.c
  461.  * Use V36 include files.
  462.  */
  463.  
  464. #include <string.h>
  465. #include <intuition/intuition.h>
  466. #include <intuition/screens.h>
  467. #include <libraries/gadtools.h>
  468. #include <graphics/displayinfo.h>
  469. #include <graphics/text.h>
  470. #include <exec/memory.h>
  471. #include <exec/ports.h>
  472.  
  473. #include <clib/exec_protos.h>
  474. #include <clib/intuition_protos.h>
  475. #include <clib/graphics_protos.h>
  476. #include <clib/gadtools_protos.h>
  477. #include <clib/alib_protos.h>
  478.  
  479. #include <pragmas/exec_pragmas.h>
  480. #include <pragmas/intuition_pragmas.h>
  481. #include <pragmas/graphics_pragmas.h>
  482. #include <pragmas/gadtools_pragmas.h>
  483.  
  484. #define SWITCH 888
  485. #define QUIT   999
  486.  
  487. struct IntuitionBase *IntuitionBase;
  488. struct GfxBase *GfxBase;
  489. struct Library *GadToolsBase;
  490.  
  491. void main(void);
  492. void ShowDisplayModes(struct List * dlist);
  493. struct Screen *OpenAScreen(struct DimensionInfo * di, UBYTE * name,
  494.                ULONG overscantype);
  495. struct Window *OpenAWindow(struct Screen * screen, ULONG overscantype);
  496.  
  497. struct DisplayNode {
  498.     struct Node dn_Node;
  499.     struct DimensionInfo dn_Dimensioninfo;
  500. };
  501.  
  502. /* The workbench compatible pens we'll use for that New Look. */
  503. static UWORD dri_Pens[] = {0, 1, 1, 2, 1, 3, 1, 0, 3, ~0};
  504.  
  505. /* Gadtools menu stuff */
  506. struct NewMenu sdm_menu[] =
  507. {
  508.     {NM_TITLE, "Project", 0, 0, 0, 0,},
  509.     {NM_ITEM, "Switch Mode", "S", 0, 0, (void *) SWITCH,},
  510.     {NM_ITEM, "Set Overscan", 0, 0, 0, 0,},
  511.     {NM_SUB, "Text", 0, CHECKIT | CHECKED, ~1, (void *) OSCAN_TEXT,},
  512.     {NM_SUB, "Standard", 0, CHECKIT, ~2, (void *) OSCAN_STANDARD,},
  513.     {NM_SUB, "Max", 0, CHECKIT, ~4, (void *) OSCAN_MAX,},
  514.     {NM_SUB, "Video", 0, CHECKIT, ~8, (void *) OSCAN_VIDEO,},
  515.     {NM_ITEM, NM_BARLABEL, 0, CHECKIT, 0, 0,},
  516.     {NM_ITEM, "Quit", "Q", 0, 0, (void *) QUIT,},
  517.     {NM_END, NULL, 0, 0, 0, 0,},
  518. };
  519.  
  520. UBYTE *OScanDescr[] = {NULL, "OSCAN_TEXT", "OSCAN_STANDARD",
  521.              "OSCAN_MAX", "OSCAN_VIDEO"};
  522.  
  523. struct EasyStruct failedES =
  524. {
  525.     sizeof(struct EasyStruct), 0, "SDM",
  526.     "%s",
  527.     "OK",
  528. };
  529.  
  530. void
  531. main(void)
  532. {
  533.     struct List *dlist;
  534.     struct DisplayNode *dnode;
  535.     struct DisplayNode *wnode, *nnode;
  536.  
  537.     ULONG modeID;
  538.     ULONG skipID;
  539.  
  540.     ULONG result;
  541.     struct DisplayInfo displayinfo;
  542.     struct NameInfo nameinfo;
  543.  
  544.     /* Fails silently if not V36 */
  545.     if (IntuitionBase = OpenLibrary("intuition.library", 36)) {
  546.         if (GfxBase = OpenLibrary("graphics.library", 36)) {
  547.             if (GadToolsBase = OpenLibrary("gadtools.library", 36)) {
  548.                 if (dlist = AllocMem(sizeof(struct List), MEMF_CLEAR)) {
  549.                     NewList(dlist);
  550.  
  551.                     /*
  552.                      * Don't want duplicate entries in the list for the
  553.                      * 'default monitor', so we'll skip the the videomode
  554.                      * for which default.monitor is the alias.
  555.                      */
  556.  
  557.                     /* INVALID_ID indicates the beginning and the end
  558.              * of the list of available keys.
  559.              */
  560.                     modeID = INVALID_ID;
  561.  
  562.                     GetDisplayInfoData(NULL, (UBYTE *) & displayinfo,
  563.                        sizeof(struct DisplayInfo),
  564.                        DTAG_DISP, LORES_KEY);
  565.                     if (displayinfo.PropertyFlags & DIPF_IS_PAL)
  566.                         skipID = PAL_MONITOR_ID;
  567.                     else
  568.                         skipID = NTSC_MONITOR_ID;
  569.                     while ((modeID = NextDisplayInfo(modeID)) != INVALID_ID) {
  570.                         if ((modeID & MONITOR_ID_MASK) != skipID) {
  571.                 /*
  572.                  * For this example,only 'named' keys are accepted.  Others
  573.                  * which have no description are left out
  574.                   * even though they may be available.
  575.                   * HAM and EXTRAHALFBRIGHT are examples of this.
  576.                   * If needed a name could be made like '320x400 HAM Interlace'.
  577.                   */
  578.  
  579.                             if (result = GetDisplayInfoData(NULL, 
  580.                                 (UBYTE *) & nameinfo,
  581.                                 sizeof(struct NameInfo),
  582.                                 DTAG_NAME,
  583.                                 modeID)) {
  584.                                 result = GetDisplayInfoData(NULL,
  585.                                 (UBYTE *) & displayinfo,
  586.                                 sizeof(struct DisplayInfo),
  587.                                 DTAG_DISP,
  588.                                 modeID);
  589.                                 if (!(displayinfo.NotAvailable)) {
  590.                                     if (dnode = 
  591.                     (struct DisplayNode *) 
  592.                     AllocMem(sizeof(struct DisplayNode), 
  593.                          MEMF_CLEAR)) {
  594.                                         result = GetDisplayInfoData(NULL, 
  595.                            (UBYTE *) &
  596.                            (dnode->dn_Dimensioninfo),
  597.                            sizeof(struct DimensionInfo), 
  598.                            DTAG_DIMS, 
  599.                            modeID);
  600.                                         /* to keep it short: if NOMEM,
  601.                      * just don't copy
  602.                      */
  603.                                         if (dnode->dn_Node.ln_Name 
  604.                         = AllocMem(strlen(nameinfo.Name)
  605.                                + 1, MEMF_CLEAR))
  606.                                             strcpy(dnode->dn_Node.ln_Name,
  607.                            nameinfo.Name);
  608.                                         AddTail(dlist, (struct Node *) dnode);
  609.                                     } else {
  610.                                         EasyRequest(NULL, &failedES, NULL,
  611.                             "Out of memory");
  612.                                         /* Force modeID to INVALID to break */
  613.                                         modeID = INVALID_ID;
  614.                                     }
  615.                                 }
  616.                             }
  617.                         }
  618.                     }
  619.                     ShowDisplayModes(dlist);
  620.  
  621.                     wnode = (struct DisplayNode *) dlist->lh_Head;
  622.                     while (nnode = (struct DisplayNode *)
  623.                (wnode->dn_Node.ln_Succ)) {
  624.  
  625.                         if (wnode->dn_Node.ln_Name)
  626.                             FreeMem(wnode->dn_Node.ln_Name,
  627.                     strlen(wnode->dn_Node.ln_Name) +1);
  628.                         Remove((struct Node *) wnode);
  629.                         FreeMem(wnode, sizeof(struct DisplayNode));
  630.                         wnode = nnode;
  631.                     }
  632.                     FreeMem(dlist, sizeof(struct List));
  633.                 } else
  634.                     EasyRequest(NULL, &failedES, NULL, "Out of memory");
  635.                 CloseLibrary(GadToolsBase);
  636.             }
  637.             CloseLibrary(GfxBase);
  638.         }
  639.         CloseLibrary(IntuitionBase);
  640.     }
  641. }
  642.  
  643. void
  644. ShowDisplayModes(struct List * dlist)
  645. {
  646.     struct Screen *screen;
  647.     struct Window *window;
  648.     struct Gadget *glist, *gadget, *hitgadget;
  649.     struct DrawInfo *drawinfo;
  650.     struct TextFont *defaultfont;
  651.     struct TextAttr *textattr;
  652.     struct IntuiMessage *imsg;
  653.     struct NewGadget *ng;
  654.     struct Menu *menu;
  655.     struct MenuItem *item;
  656.     void *vi;
  657.     ULONG iclass, icode, code;
  658.     struct DisplayNode *dnode;
  659.     struct DimensionInfo *dimensioninfo;
  660.     ULONG overscantype = OSCAN_TEXT;
  661.     ULONG curmode = 0;
  662.     BOOL ABORT = TRUE, OK;
  663.     int i;
  664.  
  665.  
  666.     if (ng = AllocMem(sizeof(struct NewGadget), MEMF_CLEAR)) {
  667.         if (textattr = AllocMem(sizeof(struct TextAttr), MEMF_CLEAR)) {
  668.             if (textattr->ta_Name = AllocMem(48, MEMF_CLEAR)) {
  669.  
  670.                 dnode = (struct DisplayNode *) dlist->lh_Head;
  671.  
  672.                 if (menu = CreateMenus(sdm_menu, TAG_DONE)) {
  673.                     do {
  674.                         dimensioninfo = &(dnode->dn_Dimensioninfo);
  675.                         OK = FALSE;
  676.                         if (screen = OpenAScreen(dimensioninfo, 
  677.                          dnode->dn_Node.ln_Name, 
  678.                          overscantype)) {
  679.                             drawinfo = GetScreenDrawInfo(screen);
  680.                             defaultfont = drawinfo->dri_Font;
  681.                             strcpy(textattr->ta_Name, 
  682.                    defaultfont->tf_Message.mn_Node.ln_Name);
  683.  
  684.                             textattr->ta_YSize = defaultfont->tf_YSize;
  685.                             textattr->ta_Style = defaultfont->tf_Style;
  686.                             textattr->ta_Flags = defaultfont->tf_Flags;
  687.  
  688.                             if (window = OpenAWindow(screen, overscantype)) {
  689.                                 vi = GetVisualInfo(screen, TAG_END);
  690.                                 if (LayoutMenus(menu, vi, TAG_DONE)) {
  691.                                     if (gadget = CreateContext(&glist)) {
  692.                                         ng->ng_LeftEdge = 
  693.                       window->BorderLeft + 10;
  694.                                         ng->ng_TopEdge = 
  695.                       window->BorderTop + 10;
  696.                                         ng->ng_Width = 
  697.                       window->Width -
  698.                         (window->BorderLeft + 10) -
  699.                           (window->BorderRight + 10);
  700.                                         ng->ng_Height =
  701.                       window->Height -
  702.                         (window->BorderTop + 10) -
  703.                           (window->BorderBottom + 10) -
  704.                         (4 + defaultfont->tf_YSize + 2);
  705.                                         ng->ng_TextAttr = textattr;
  706.                                         ng->ng_GadgetText = NULL;
  707.                                         ng->ng_VisualInfo = vi;
  708.                                         ng->ng_GadgetID = 1;
  709.                                         ng->ng_Flags = PLACETEXT_ABOVE;
  710.                                         gadget =
  711.                       CreateGadget(LISTVIEW_KIND, gadget,
  712.                                ng, GTLV_Labels, dlist,
  713.                                GTLV_ShowSelected, NULL,
  714.                                GTLV_Selected, curmode,
  715.                                TAG_END);
  716.  
  717.                                         ng->ng_TopEdge +=
  718.                       gadget->Height +
  719.                         defaultfont->tf_YSize + 10;
  720.                                         ng->ng_Width = 80;
  721.                                         ng->ng_LeftEdge =
  722.                       ((window->Width - window->BorderLeft
  723.                         - window->BorderRight) / 2) - 30;
  724.                                         ng->ng_Height = defaultfont->tf_YSize + 8;
  725.                                         ng->ng_GadgetID = 2;
  726.                                         ng->ng_GadgetText = "OK";
  727.                                         ng->ng_VisualInfo = vi;
  728.                                         ng->ng_Flags = PLACETEXT_IN;
  729.                                         gadget = 
  730.                       CreateGadget(BUTTON_KIND, gadget,
  731.                                ng, TAG_END);
  732.  
  733.                                         AddGList(window, glist, -1, -1, NULL);
  734.                                         RefreshGList(glist, window, NULL, -1);
  735.                                         GT_RefreshWindow(window, NULL);
  736.                                         SetMenuStrip(window, menu);
  737.                                         ABORT = FALSE;
  738.                                     } else
  739.                                         EasyRequest(window, &failedES, NULL, 
  740.                             "Can't create gadget context");
  741.                                 } else
  742.                                     EasyRequest(window, &failedES, NULL, 
  743.                         "Can't layout menus");
  744.  
  745.                                 do {
  746.                                     WaitPort(window->UserPort);
  747.                                     while (imsg = GT_GetIMsg(window->UserPort)) {
  748.                                         iclass = imsg->Class;
  749.                                         icode = imsg->Code;
  750.                                         hitgadget = 
  751.                       (struct Gadget *) imsg->IAddress;
  752.                                         GT_ReplyIMsg(imsg);
  753.  
  754.                                         switch (iclass) {
  755.                                         case GADGETUP:
  756.                                             if (hitgadget->GadgetID == 1) {
  757.                                                 dnode = 
  758.                           (struct DisplayNode *) 
  759.                             dlist->lh_Head;
  760.                                                 for (i = 0; i < icode; i++)
  761.                                                 dnode = 
  762.                           (struct DisplayNode *)
  763.                             dnode->dn_Node.ln_Succ;
  764.                                                 curmode = i;
  765.                                             }
  766.                                             if (hitgadget->GadgetID == 2)
  767.                                                 OK = TRUE;
  768.                                             break;
  769.                                         case MENUPICK:
  770.                                             while ((icode != MENUNULL) 
  771.                            && (ABORT == FALSE)) {
  772.                                                 item = ItemAddress(menu, icode);
  773.  
  774.                                                 code = (ULONG) MENU_USERDATA(item);
  775.                                                 if (code == QUIT)
  776.                                                     ABORT = TRUE;
  777.                                                 else if
  778.                                                     (code == SWITCH)
  779.                                                     OK = TRUE;
  780.                                                 else
  781.                                                     overscantype = (ULONG) code;
  782.                                                 icode = item->NextSelect;
  783.                                             }
  784.                                             break;
  785.                                         case CLOSEWINDOW:
  786.                                             ABORT = TRUE;
  787.                                             break;
  788.                                         }
  789.                                     }
  790.                                 } while (ABORT == FALSE && OK == FALSE);
  791.                                 ClearMenuStrip(window);
  792.                                 CloseWindow(window);
  793.                                 FreeVisualInfo(vi);
  794.                                 FreeGadgets(glist);
  795.                             } else
  796.                                 EasyRequest(NULL, &failedES, NULL, 
  797.                         "Can't open window");
  798.                             FreeScreenDrawInfo(screen, drawinfo);
  799.                             CloseScreen(screen);
  800.                         } else
  801.                             EasyRequest(NULL, &failedES, NULL, 
  802.                     "Can't open screen");
  803.                     } while (ABORT == FALSE);
  804.                     FreeMenus(menu);
  805.                 } else
  806.                     EasyRequest(NULL, &failedES, NULL, "Can't create menus");
  807.                 FreeMem(textattr->ta_Name, 48);
  808.             } else
  809.                 EasyRequest(NULL, &failedES, NULL, "Out of memory");
  810.             FreeMem(textattr, sizeof(struct TextAttr));
  811.         } else
  812.             EasyRequest(NULL, &failedES, NULL, "Out of memory");
  813.         FreeMem(ng, sizeof(struct NewGadget));
  814.     } else
  815.         EasyRequest(NULL, &failedES, NULL, "Out of memory");
  816. }
  817.  
  818.  
  819. /*
  820.  * It's advised to use one of the overscan constants and
  821.  * STDSCREENWIDTH and STDSCREENHEIGHT. For this example however, we'll
  822.  * skip all that an use QueryOverscan to get the rectangle describing the
  823.  * requested overscantype and pass that as the displayclip description.
  824.  * Actually, since we pass the standard rectangle from the display database,
  825.  * it is equivalent to the prefered:
  826.  *
  827.  * screen = OpenScreenTags(NULL,
  828.  *                         SA_DisplayID, di->Header.DisplayID,
  829.  *                         SA_Overscan, overscantype,
  830.  *                         SA_Width, STDSCREENWIDTH,
  831.  *                         SA_Height, STDSCREENHEIGHT,
  832.  *                         SA_Title, name,
  833.  *                         SA_Depth, 2,
  834.  *                         SA_SysFont, 1,
  835.  *                         SA_Pens, dri_Pens,
  836.  *                         TAG_END);
  837.  */
  838.  
  839. struct Screen *
  840. OpenAScreen(struct DimensionInfo * di, UBYTE * name, ULONG overscantype)
  841. {
  842.  
  843.     struct Rectangle rectangle;
  844.  
  845.     /* Can't fail, already made sure it's a valid displayID */
  846.     QueryOverscan(di->Header.DisplayID, &rectangle, overscantype);
  847.  
  848.  
  849.     return (OpenScreenTags(NULL,
  850.                            SA_DisplayID, di->Header.DisplayID,
  851.                            SA_DClip, &rectangle,
  852.                            SA_Title, name,
  853.                            SA_Depth, 2,
  854.                            SA_SysFont, 1,   /* Use the prefered WB screen font */
  855.                            SA_Pens, dri_Pens,
  856.                            TAG_END));
  857. }
  858.  
  859. struct Window *
  860. OpenAWindow(struct Screen * screen, ULONG overscantype)
  861. {
  862.     return (OpenWindowTags(NULL,
  863.                            WA_Top, screen->BarHeight + 1,
  864.                            WA_Height, screen->Height - (screen->BarHeight + 1),
  865.                            WA_CustomScreen, screen,
  866.                            WA_IDCMP, CLOSEWINDOW | LISTVIEWIDCMP | MENUPICK,
  867.                            WA_Flags, WINDOWCLOSE | ACTIVATE,
  868.                            WA_Title, OScanDescr[overscantype],
  869.                            TAG_END));
  870. }
  871.  
  872.  
  873.